﻿/**
 * ...
 * @author alijaya
 */

package homponex.utils;

class DynamicUtils 
{

	public static function mergeDynamic(main:Dynamic, add:Dynamic)
	{
		if (main == null || add == null) return;
		for (n in Reflect.fields(add))
		{
			Reflect.setField(main, n, Reflect.field(add, n));
		}
	}
	
	public static function notNull<T>(prop:T, ifnull:T) : T
	{
		return (prop != null)? prop : ifnull;
	}
	
	public static function getClassName(c:Class<Dynamic>) : String
	{
		var className:String = Type.getClassName(c);
		var a:Array<String> = className.split(".");
		className = a[a.length - 1];
		return className;
	}
	
	public static function getClassTree(c:Class<Dynamic>) : String
	{
		var name:String = "";
		var iC:Class<Dynamic> = Type.getSuperClass(c);
		if ( iC != null) name += getClassTree(iC);
		
		var className:String = getClassName(c);
		if (name.length != 0) name += ".";
		name += className;
		return name;
	}
	
}